﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml;


namespace x.paypal.model
{
    public class ExecutePayRequest:IExcecutePayRequest
    {
        /// <summary>
        /// We always send XML
        /// </summary>
        XDocument doc = null;
        XNamespace payPalNamespace = "http://svcs.paypal.com/types/ap";
        string request = "ExecutePaymentRequest";
        #region IPayRequest Members

        public IExcecutePayRequest CreateRequest()
        {

            doc = new XDocument
            (

               new XElement(payPalNamespace + request,
                   new XElement("requestEnvelope",
                   new XElement("errorLanguage", "en_US"))
                   ));
            XElement a = new XElement("actionType", ActionType.PAY.ToString());
            doc.Element(payPalNamespace + "ExecutePaymentRequest").Add(a);
            return this; 
        }
        public IExcecutePayRequest WithPayKey(string payKey)
        {
            XElement a = new XElement("payKey", payKey);
            doc.Element(payPalNamespace + "ExecutePaymentRequest").Add(a);
            return this;
        }
        public XElement AsXML
        {
            get 
            {
                return XElement.Parse(doc.ToString()); 
            }
        }
        #endregion





        public string PaymentReference
        {
            get { throw new NotImplementedException(); }
        }
    }
}